import { config } from 'lin-mizar';
import { Sequelize } from 'sequelize';

/**
 * 数据库名，默认lin-cms
 */
const database = config.getItem('db.database', 'lincms');

/**
 * 数据库用户名，默认root
 */
const username = config.getItem('db.username', 'root');

/**
 * 数据库密码，默认123456
 */
const password = config.getItem('db.password', 'root');

// const port = config.getItem('db.port', '3306');

// const dialect = config.getItem('db.dialect', 'mysql');
// const host = config.getItem('db.host', 'localhost');
/**
 * 其它数据库配置项
 */
const options = config.getItem('db', {
  host: '127.0.0.1',
  dialect: 'mysql',
  port: 3306,
  define: {
    timestamps: false
  }
});

/**
 * 全局的 Sequelize 实例
 */
const sequelize = new Sequelize(database, username, password, {
  ...options
});

sequelize.sync({
  force: false
});

export default sequelize;
